package com.atguigu.spzx.service.user.controller;

import com.atguigu.spzx.service.user.service.UserAddressService;
import com.atguigu.spzx.model.common.Result;
import com.atguigu.spzx.model.entity.h5.UserAddress;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title:
 * author: zgl
 * date: 2024/1/18
 * description：
 */
@RestController
@RequestMapping("/api/user/userAddress")
public class UserAddressController {
    @Resource
    private UserAddressService userAddressService;

    @Operation(summary = "获取用户地址列表")
    @GetMapping("/auth/findUserAddressList")
    public Result findUserAddressList() {
        List<UserAddress> addressList = userAddressService.findUserAddressList();
        return Result.ok(addressList);
    }

    @Operation(summary = "删除用户地址接口")
    @DeleteMapping("/auth/removeById/{id}")
    public Result removeById(@PathVariable Long id) {
        userAddressService.deleteById(id);
        return Result.ok();
    }

    @Operation(summary = "修改用户地址接口")
    @PutMapping("/auth/updateById")
    public Result updateById(@RequestBody UserAddress userAddress) {
        //System.out.println(userAddress);
        userAddressService.updateAddress(userAddress);
        return Result.ok();
    }

    @Operation(summary = "添加用户地址接口")
    @PostMapping("/auth/save")
    public Result save(@RequestBody UserAddress userAddress) {
        userAddressService.addAddress(userAddress);
        return Result.ok();
    }

    @Operation(summary = "获取指定用户地址接口")
    @GetMapping("/getUserAddress/{id}")
    public Result<UserAddress> getUserAddress(@PathVariable Long id) {
        UserAddress userAddress = userAddressService.getById(id);
        return Result.ok(userAddress);
    }
}
